package cn.damai.mine.json.jsonfield;


import cn.damai.mine.json.fastjson.Weibo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class PersonTest {
	
	/**
	 * http://blog.csdn.net/u011425751/article/details/51219242
	 * 
	 * @JSONField注解
	 */
	
	private static Person person;

	static void init() {
		person = new Person();
		person.setName("xianglj");
		person.setAge("20");
		person.setDesc("ֻ��һ������");
	}

	public static void main(String[] args) {

		init();

		String jsonStr = JSONObject.toJSONString(person);
		System.out.println("bean to json:" + jsonStr);

		// �ı�json��keyΪ��д
		jsonStr = jsonStr.toUpperCase();

		System.out.println("��Ҫת����json:" + jsonStr);
		person = JSONObject.toJavaObject(JSONObject.parseObject(jsonStr),
				Person.class);
		System.out.println("json to bean:" + person.getName());

		System.out.println("===========jsonWithJSONField=============");// JSONField�����ִ�Сд

		String s = "{\"id\":\"0375\",\"city\":\"ƽ��ɽ\",\"otherId\":\"10020\"}";

		Weibo weibo = JSON.parseObject(s, Weibo.class);
		System.out.println(weibo.getId() + weibo.getCity() + weibo.getName());

		Weibo weibo2 = JSONObject.parseObject(s, Weibo.class);
		System.out.println(weibo2.getId() + weibo2.getCity() + weibo.getName());

	}

}
